#include "Effect.h"
#include "Technique.h"

Effect::Effect(void)
{
}

Effect::~Effect(void)
{
	// delete all techniques.
	TechIt it;
	for ( it = m_TechniqueMap.begin(); it != m_TechniqueMap.end(); it++)
	{
		delete it->second;
	}
	// delete all the parameters.
	vector<FXParameter*>::iterator parameterIt;
	for ( parameterIt = m_AllParameters.begin(); parameterIt != m_AllParameters.end(); parameterIt++)
	{
		delete (*parameterIt);
	}
}



Technique* Effect::GetTechnique(tstring name) const
{
	TechIt it = m_TechniqueMap.find(name);
	if ( it != m_TechniqueMap.end() )
		return it->second;
	else
		return NULL;
}

void Effect::AddTechnique(Technique* technique)
{
	m_TechniqueMap[technique->GetName()]=technique;
}


FXParameter* Effect::FindParameterByName(const tstring& name) const
{
	TechIt it;
	for ( it = m_TechniqueMap.begin() ; it!=m_TechniqueMap.end(); it++)
	{
		Technique* t = it->second;
		FXParameter* p = t->FindParameterByName(name);
		if ( p != NULL )
			return p;
	}
	return NULL;
}


FXParameter* Effect::FindParameterBySemantic(const tstring& name) const
{
	TechIt it; 
	for ( it = m_TechniqueMap.begin() ; it!=m_TechniqueMap.end(); it++)
	{
		Technique* t = it->second;
		FXParameter* p = t->FindParameterBySemantic(name);
		if ( p != NULL )
			return p;
	}
	return NULL;
}

void Effect::AddParameter(FXParameter* parameter)
{
	m_AllParameters.push_back(parameter);
}